import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/home/index.vue'),
    meta: {
      title: '首页',
      showTabBar: true
    }
  },
  {
    path: '/airplane',
    name: 'Airplane',
    component: () => import('@/views/airplane/index.vue'),
    meta: {
      title: '当股东',
      showTabBar: true
    }
  },
  {
    path: '/camp',
    name: 'Camp',
    component: () => import('@/views/camp/index.vue'),
    meta: {
      title: '建营地',
      showTabBar: true
    }
  },
  {
    path: '/video',
    name: 'Video',
    component: () => import('@/views/video/index.vue'),
    meta: {
      title: '视频',
      showTabBar: true
    }
  },
  {
    path: '/my',
    name: 'My',
    component: () => import('@/views/my/index.vue'),
    meta: {
      title: '我的',
      showTabBar: true
    }
  },
  {
    path: '/video-detail',
    name: 'VideoDetail',
    component: () => import('@/views/video/detail.vue'),
    meta: {
      title: '视频详情',
      showTabBar: false
    }
  },
  {
    path: '/product-info',
    name: 'ProductInfo',
    component: () => import('@/views/airplane/product-info.vue'),
    meta: {
      title: '产品详情',
      showTabBar: false
    }
  },
  // {
  //   path: '/orders',
  //   name: 'Orders',
  //   component: () => import('@/views/orders/index.vue'),
  //   meta: {
  //     title: '我的订单',
  //     showTabBar: false
  //   }
  // },
  // {
  //   path: '/wallet',
  //   name: 'Wallet',
  //   component: () => import('@/views/wallet/index.vue'),
  //   meta: {
  //     title: '我的钱包',
  //     showTabBar: false
  //   }
  // },
  // {
  //   path: '/settings',
  //   name: 'Settings',
  //   component: () => import('@/views/settings/index.vue'),
  //   meta: {
  //     title: '设置',
  //     showTabBar: false
  //   }
  // },
  // {
  //   path: '/login',
  //   name: 'Login',
  //   component: () => import('@/views/login/index.vue'),
  //   meta: {
  //     title: '登录',
  //     showTabBar: false
  //   }
  // }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

// 全局前置守卫，设置页面标题
router.beforeEach((to, from, next) => {
  // 设置页面标题
  document.title = to.meta.title || '中空领航'
  
  // 这里可以添加登录验证等逻辑
  // const isAuthenticated = localStorage.getItem('token')
  // if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
  // else next()
  
  next()
})

export default router